#include "DisplayRBJ.h"

DisplayRBJ::DisplayRBJ(void)
{
}


DisplayRBJ::~DisplayRBJ(void)
{
}

float CartTotal::getTotal(){
	return total;
}

Cart CartTotal::getCart(){
	return cart;
}

//RBJ total checkout compare functions
bool TotCompare(CartTotal a, CartTotal b){
        return a.getTotal() > b.getTotal();
}

//RBJ display biggest total checkout
string DisplayRBJ::display(Store_menu m){
		cout << "Checking all carts takes sometime. Please wait...\n";
		vector<CartTotal> totals;
		//RBJ count all checkouts --> Takes a lot of time!!! since has to calculate cart, cart item, and product (n^3!!!)
		for(int i=0;i<m.get_carts().size();i++){
			cout << "Processing cart-" << i << "\n";
			float total = 0;
			for(int j=0; j<m.get_cart_items().size();j++){
				for(int k=0; k<m.get_prods().size();k++){
					if(m.get_carts().at(i).getCartId() == m.get_cart_items().at(j).getCartId() && m.get_prods().at(k).getProdId() == m.get_cart_items().at(j).getProdId()){
						total += m.get_cart_items().at(j).getProdQty() * m.get_prods().at(k).getProdPrice();
					}
				}
			}
			CartTotal ct(m.get_carts().at(i),total);
			totals.push_back(ct);
		}
		sort(totals.begin(), totals.end(), TotCompare);
		
		//product display format
		stringstream sline (stringstream::in | stringstream::out);
		sline << "The Biggest Total Checkout Cart\n";
		sline << "CartID : " << totals.at(0).getCart().getCartId()<<"\n";
		sline << "CustID : " << totals.at(0).getCart().getCustId()<<"\n";
		sline << "Date : " << totals.at(0).getCart().getPurchaseDate()<<"\n";
		sline << "Total : " << totals.at(0).getTotal()<<"\n";		
		cout << sline.str();
		return sline.str();	
		
}